<!--
 * @Author: your name
 * @Date: 2022-01-06 11:32:14
 * @LastEditTime: 2022-01-07 10:37:19
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \elementui\src\views\Login.vue
-->
<template>
   
  <div class="myform">
       
    <el-form :model="myform" status-icon :rules="rules" label-width="100px">
           
      <elFormItem label="用户" prop="user">
                <el-input v-model="myform.user" type="text" />      
      </elFormItem>
           
      <el-form-item label="密码" prop="pass">
                <el-input v-model="myform.pass" type="password" />      
      </el-form-item>
         
    </el-form>
     
  </div>
</template>
<script>
export default {
  name: "Login",
  data() {
    return {
      myform: {
        user: "lisi",
        pass: "123456",
      },
      rules: {
        //根据prop的值正则验证
        user: [
          {
            required: true,
            message: "输入有误哦",
            trigger: "blur",
            pattern: /123456/,
          },
        ],
        pass: [
          {
            validator: (rule, value, cb)=>{
              //自定义校验
              console.log(rule);
              console.log(value);
              console.log(cb);
              let reg = /^(123)\w(456)$/;
              let a = reg.test(value);
              if (a) {
                return cb();
              } else {
                return cb(new Error()); //返回的执行cb()表示通过，返回执行cb(new Error('没通过'))
              }
            },
            message: "验证没有通过",
            trigger: "blur", //什么时候触发校验规则 blur失去焦点
          },
        ],
      },
    };
  },
};
</script>